package com.ztgf.commodity.service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;

import javax.annotation.Resource;

import com.ztgf.commodity.common.config.YmlConfig;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.ztgf.commodity.mapper.CommodityArrivalGoodsRemindMapper;
import com.ztgf.commodity.models.service.ICommodityArrivalGoodsRemindService;
import com.ztgf.commodity.models.bo.CommodityArrivalGoodsRemindSaveBO;
import com.ztgf.commodity.models.dto.CommodityArrivalGoodsRemindDTO;

import java.util.Arrays;
import java.util.List;

/**
 * 商品到货提醒表控制器
 *
 * @author chenyu.wang
 * @Date 2020-06-23 15:58:01
 */
@DubboService
public class CommodityArrivalGoodsRemindServiceImpl extends ServiceImpl<CommodityArrivalGoodsRemindMapper, CommodityArrivalGoodsRemindDTO> implements ICommodityArrivalGoodsRemindService {

    @Resource
    private YmlConfig ymlConfig;

    @Override
    public boolean add(CommodityArrivalGoodsRemindSaveBO saveBO) {
        CommodityArrivalGoodsRemindDTO dto = new CommodityArrivalGoodsRemindDTO();
        BeanUtils.copyProperties(saveBO, dto);
        String[] split = saveBO.getAtrrComboIds().split(",");
        Arrays.sort(split);
        String atrr = String.join(",", split);//给属性id排序之后再保存
        dto.setId(ymlConfig.getPkId());
        dto.setAtrrComboIds(atrr);
        return this.insert(dto);
    }

    @Override
    public List<CommodityArrivalGoodsRemindDTO> queryList(Long goodsId, String attrIds) {
        String[] split = attrIds.split(",");
        Arrays.sort(split);
        String atrr = String.join(",", split);//给属性id排序之后再保存
        Wrapper<CommodityArrivalGoodsRemindDTO> wrapper = new EntityWrapper<>();
        wrapper.eq("commodity_id", goodsId)
                .eq("atrr_combo_ids", atrr);
        return this.selectList(wrapper);
    }
}
